/*
 * author: Tim
 * date:2021.9.16
 */
class student
{
    private:
        std::string id;
        int math_grade;
        int english_grade;
        int computer_grade;
        std::string name;
        int total;
        double avg;

    public:
        student();
        void set_stu_inf(std::istringstream& info);
        std::string get_reg_num();
        int Sum();
        double Average();
        void print();
        void print(std::ostringstream&);
        void get_by_id(std::string _id);
        void get_by_id(std::string _id, std::ostringstream& pass);
        bool operator < (student other);
        bool operator > (student other);
        bool operator <= (student other);
        ~student() {};
};

student::student(): id(""), math_grade(0),
    english_grade(0), computer_grade(0), name(""), total(0), avg(0) {}
void student::set_stu_inf(std::istringstream& info)
{
    info>>id>>math_grade>>english_grade>>computer_grade>>name;
    Sum();
    Average();
}
std::string student::get_reg_num()
{
    return id;
}
int student::Sum()
{
    if (!total) total = math_grade + english_grade + computer_grade;
    return total;
}
double student::Average()
{
    avg = ((double)total) / 3;
    return avg;
}
void student::print()
{
    std::cout<<"----------------------------\n"
             <<"Name: "<<name<<"\n"
             <<"ID: "<<id<<"\n"
             <<"Math: "<<math_grade<<"\n"
             <<"English: "<<english_grade<<"\n"
             <<"Computer: "<<computer_grade<<"\n"
             <<"Total: "<<total<<"\n"
             <<"Average: "<<avg<<"\n"
             <<"----------------------------\n";
}
void student::print(std::ostringstream& pass)
{
    pass<<"----------------------------\n"
        <<"Name: "<<name<<"\n"
        <<"ID: "<<id<<"\n"
        <<"Math: "<<math_grade<<"\n"
        <<"English: "<<english_grade<<"\n"
        <<"Computer: "<<computer_grade<<"\n"
        <<"Total: "<<total<<"\n"
        <<"Average: "<<avg<<"\n"
        <<"----------------------------\n";
}
void student::get_by_id(std::string _id)
{
    if (_id == id) print();
}
void student::get_by_id(std::string _id, std::ostringstream& pass)
{
    if (_id == id) print(pass);
}
bool student::operator < (student other)
{
    return (total < other.total);
}
bool student::operator > (student other)
{
    return (total > other.total);
}
bool student::operator <= (student other)
{
    return (total <= other.total);
}
